package czy.demo.controller;

import org.apache.hadoop.fs.FileStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.fs.FsShell;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

/**
 * FsShell是spring提供的以类似于shell形式操作hdfs文件系统的自动配置Bean
 * 需要在application.yml中启用
 */
@RestController
@RequestMapping("/fs")
public class FsShellController {

    private static final Logger logger = LoggerFactory.getLogger(FsShellController.class);

    @Autowired
    private FsShell fsShell;

    /**
     * 显示指定目录下文件状态
     * @param url
     * @return
     */
    @GetMapping("/ls/{url}")
    public Collection<FileStatus> ls(@PathVariable String url){
        logger.info("查看目录"+url+"下的文件状态");
        return this.fsShell.ls(url);
    }


}
